
<!doctype html>
<html>

<head>
<meta charset="utf-8">
<title>后台管理模板</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta charset="utf-8">
<link rel="stylesheet" href="@{'/public/plugins/layui/css/layui.css'}" media="all">
<script src="@{'public/plugins/layui_new/layui.js'}"></script>
<script src="@{'public/js/jquery-2.1.4.min.js'}"></script>


</head>
<body>


	<!-- 内容主体区域 -->
	<div style="padding: 15px;">
		<ul class="layui-tab-title">

			<button class="layui-btn" onclick="addOrupdate()">
				<i class="layui-icon">&#xe608;</i> 添加信息
			</button>
		</ul>

		<form class="layui-form" action="">
			<table class="layui-table">
				<thead>
					<tr>
						<th lay-data="{field:'id', width:80, sort: true}">ID</th>
						<th lay-data="{field:'name', width:200, sort: true}">用户名</th>
						<th lay-data="{field:'enable', width:50, sort: true}">是否启用</th>
						<th lay-data="{field:'bianji', width:150}">操作</th>
					</tr>
				</thead>
				#{list items:page.result,as:'item'}
				<tr>
					<td>${item.id}</td>
					<td>${item.name}</td>
					<td>
					    #{if item.enable==1 }
					    <i class="layui-icon" style="font-size: 30px; color: #1E9FFF;"> &#xe616;</i>
					    #{/if}
					    #{else}
					    <i class="layui-icon" style="font-size: 30px; color: #999999;">  &#x1007;</i>
					    #{/else}
					</td>

					<td><a
						onclick="addOrupdate(${item.id},'${item.name}','${item.enable}')"
						target="_blank" class="layui-btn layui-btn-normal layui-btn-mini">编辑</a>
						<a href="javascript:deleteById(${item.id},'${item.name}')"
						class="layui-btn layui-btn-mini layui-btn-warm">删除</a></td>
				</tr>
				#{/list}
			</table>

		</form>
	</div>




	<script>
	//JavaScript代码区域
	layui.use('element', function(){
	  var element = layui.element;
	  
	});
	
	layui.use(['layer', 'form'], function(){
		  var layer = layui.layer
		  ,form = layui.form;
	});
	
	layui.use('table', function(){
	  var table = layui.table;
	  
	});
	//删除
	 function deleteById(id,name){
		 layer.confirm('<span  style="font-size:12px;color:red">(删除一级目录,会删除与之有关联的二级目录及商品)</span></br>确认删除《<b style="color:red">'+name+'</b>》该目录吗？', {btn: ['确定','关闭']},
			function(index, layero){
			 	layer.prompt({
				  formType: 0,
				  value: '初始值',
				  title: '请确认要删除的目录！',
					}, function(value, index, elem){
						if(value==name){
							$.ajax({
							 	url: "@{manage.deleteOneById()}",
								type: "GET",
								async:false,
								data:{"id":id},
								dataType: "text",
								success: function(data) {
									if(data){
										 layer.confirm('删除成功！</br>', {
									        btnAlign: 'c',
									        btn: ['确定']
									      },function()
									      {window.location.href="/manageLevelOne";}
									      ); 
									}else{
										layer.alert("删除失败!");
									}
								},
								error: function(data) {
									layer.alert("您的账户可能出现异常，请重新刷新获取账号信息!");
								}
					  	}) 
					}else{
						layer.alert("您输入的目录不正确！<br/>请重新输入！");
					}
						
				});
 		 	}
	 	); 
	} 
	 // 添加或修改窗体
	 function addOrupdate(id,name,state){
		 if(id == null || id == undefined || id == ""){
			 tit="添加";
		 }else{
			 tit="修改";
		 }
		 $("#editId").val("");
		 $("#editName").val(name);
		 $("#editId").val(id);
		 $("#oneEnable").prop("checked",true)
		 if(state==1){
		 }
		 layer.open({
			  type: 1,
			  title:tit+"信息",
			  content: $('.edit-innerWarning'),
			  area: ['400px', '']
			});	
	 }
	 
		//关闭弹窗
		function  close(){
			layer.closeAll()	
		}
		//新增或者修改
		function addOrUp(id){
			var data=$("#OneaddOrupID").serialize();
			 $.ajax({
				 	url: "@{manage.updateOrAddMLOne()}",
					type: "GET",
					async:false,
					data:data,
					dataType: "text",
					success: function(data) {
						if(data){
							 layer.confirm(tit+'成功！</br>', {
							        btnAlign: 'c',
							        btn: ['确定']
						      },function()
							      {window.location.href="/manageLevelOne";}
						      ); 
						}else{
							layer.alert("失败!");
						}
					},
					error: function(data) {
						layer.alert("您的账户可能出现异常，请重新刷新获取账号信息!");
					}
		  	})
		}
	</script>
	
	<div class="edit-innerWarning" hidden="hidden"
		style="padding: 17px 0 20px 30px;">
	<form class="layui-form" action="" id="OneaddOrupID">
		<input id="editId" name="oneQuery.id" type="text" hidden="hidden">
		<div class="layui-form-item layui-block">
			<label class="layui-form-label">目录名称</label>
			<div class="layui-input-inline">
				<input id="editName" type="text" name="oneQuery.name" required
					lay-verify="required" placeholder="必填项" class="layui-input">
			</div>
		</div>
		
		<div class="layui-form-item layui-block">
			<label id ="testId" class="layui-form-label">状态：</label>
			<div class="layui-input-inline" id="hidden">
				<input type="checkbox"  name="oneQuery.enable" lay-skin="switch" lay-filter="switchTest" id='oneEnable'
					lay-text="启用|停用" value="1"   >
			</div>
		</div>

		<div class="operate-btn"  style="text-align: center;">

			<a href="javascript:addOrUp()" class="layui-btn layui-btn-small">确认</a>
			<a href="javascript:close();"
				class="layui-btn layui-btn-primary layui-btn-small">取消</a>
		</div>
	</form>
	</div>
</body>
</html>
